//
//  ATScriptSuite.m
//  AutomationTool
//
//  Created by Laurie Marmon on 2/26/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "ATScriptSuite.h"
#import "ATScript.h"

#pragma mark Private Properties

@interface ATScriptSuite ()

@property (nonatomic, strong) NSString *name;
@property (nonatomic, strong) NSMutableArray *scriptsStorage;

@end

#pragma mark Main Class Implementation

@implementation ATScriptSuite

@synthesize name = _name;
@synthesize scriptsStorage = _scriptsStorage;

- (id)init
{
    self = [super init];
    if (self) {
        self.scriptsStorage = [[NSMutableArray alloc] init];
    }
    return self;
}

- (NSString *)description
{
    return [NSString stringWithFormat:@"Scripts=%@", self.scriptsStorage.description];
}

- (void)encodeWithCoder:(NSCoder *)aCoder {
    [aCoder encodeObject:_name forKey:@"ATScriptSuiteName"];
    [aCoder encodeObject:_scriptsStorage forKey:@"ATScriptsStorage"];
}

- (id)initWithCoder:(NSCoder *)aDecoder {
    self = [super init];
    _name = [aDecoder decodeObjectForKey:@"ATScriptName"];
    _scriptsStorage = [aDecoder decodeObjectForKey:@"ATScriptsStorage"];
    return self;
}

- (void)insertScript:(ATScript *)script atIndex:(NSUInteger)index 
{
    [self willChangeValueForKey:@"scripts"];
    [self.scriptsStorage insertObject:script atIndex:index];
    [self didChangeValueForKey:@"scripts"];
}

- (void)removeScript:(ATScript *)script
{
    [self willChangeValueForKey:@"scripts"];
    [self.scriptsStorage removeObject:script];
    [self didChangeValueForKey:@"scripts"];
}

- (NSArray *)scripts
{
    return self.scriptsStorage;
}

@end
